package com.lw.controller;

import com.alibaba.fastjson.JSONObject;
import com.lw.common.utils.ResultVo;
import com.lw.service.IndexService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@Tag(name = "首页接口", description = "首页统计相关接口")
@RequestMapping("/index")
public class IndexController {
    @Resource
    private IndexService indexService;

    /**
     * 统计首页信息
     * @return 统计信息 --地图联动效果
     **/
    @Operation(
            summary = "统计首页信息",
            description = "获取首页的统计信息，以 JSON 格式返回-地图联动效果"
    )
    @ApiResponse(
            responseCode = "200",
            description = "成功获取首页统计信息",
            content = @Content(
                    schema = @Schema(
                            type = "object",
                            description = "首页统计信息，包含以下字段：\n" +
                                    "- `countUser`: 用户统计数。\n" +
                                    "- `countInterface`: 接口统计数。\n" +
                                    "- `listInterface`: 接口列表。\n"+
                                    "- `totalServiceCount`: 统计接口调用次数。\n"+
                                    "- `countAlarmL1`: 告警统计数等级1。\n"+
                                    "- `countAlarmL3`: 告警统计数等级3。\n"+
                                    "- `userList`: 服务用户列表。\n"
                    )
            )
    )
    @GetMapping("/statIndex")
    public ResultVo<JSONObject> statIndex(String location) {
        return ResultVo.success(indexService.statIndex(location));
    }

}
